<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.beans.EndpointBean" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.utils.GetDocumentUtil" %>
<%@ page import="org.wso2.carbon.registry.common.utils.RegistryUtil" %>
<%@ page import="org.wso2.carbon.registry.common.ui.UIException" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.clients.TopicServiceClient" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.beans.xsd.TagBean" %>
<%@ page import="org.wso2.carbon.registry.custom.dia.ui.beans.xsd.AssociationBean" %>

<%
    String cPath = RegistryUtil.getPath(request);
    EndpointBean bean;
    String tagString="";
    String title="xxx";
    String summary="xxx";
    String externalLink="xxx"; 
    try {
        GetDocumentUtil getDocumentUtil = new GetDocumentUtil();
        bean = getDocumentUtil.getEndpointBean(cPath, config, session);
        TopicServiceClient client = new TopicServiceClient(config, session);
        TagBean[] tagBeans = client.getTags(cPath);
        int index=0;
        if(tagBeans != null){
            for(TagBean tagBean:tagBeans){
               // tagString +="<a href=\"../search/search.jsp?criteria="+
               //         tagBean.getTagName() + "&searchType=Tag\">" +
               //         tagBean.getTagName() + "</a>, ";

               tagString +=  "<a onmouseover=\"showDelx('"+ index +
                   "')\" class=\"cloud-x1\" href=\"../search/search.jsp?searchType=tag&amp;criteria="+
                   tagBean.getTagName()+"\"> "+tagBean.getTagName()+" </a>" +
                   "<a title=\"Delete\" style=\"\" id=\"delx"+index+"\" onclick=\"delTagx('"+tagBean.getTagName()+"','"+cPath+"')\" class=\"closeButton registryWriteOperation\"> x </a>&nbsp;&nbsp;";
               index++;
            }
        }
        title = bean.getTitle();
        summary = bean.getSummary();
        externalLink = bean.getExternalLink();
    } catch (UIException e) {
        System.out.println("Error in retrieving details.");
        %>Error occured while retrieving Documentation details<%
        return;
    }
%>

<script type="text/javascript">
    function showDelx(id){
        
        var wanted = $('delx'+id);
	var all = $('tagList1').getElementsByTagName("*");
	for(var i=0;i<all.length;i++){
		if(YAHOO.util.Dom.hasClass(all[i],'closeButton')){
			all[i].style.display="none";
		}
	}
	wanted.style.display = "";
    }

    function delTagx(tag,path){
        CARBON.showConfirmationDialog(org_wso2_carbon_registry_info_ui_jsi18n["are.you.sure.you.want.to.delete.this.tag"], function() {
	        new Ajax.Request('../info/tag-delete-ajaxprocessor.jsp', {
	            method: 'post',
	            parameters: {path: path, tag: tag},
	            onSuccess: function(transport) {
                    $('tagList1').innerHTML = transport.responseText;
                    },

                    onFailure: function(transport) {
                        showRegistryError(transport.responseText);
                    }
	        });

	    }, null);
    }

 

</script>
<br/> 

<h3><%=title%></h3>

<table width="50%">
    <tr>
        <td class="leftCol-med">Summary</td>
        <td><%=summary%></td>
    </tr>
     <tr>
        <td class="leftCol-med">External Link</td>
        <td><a target="_blank" href="<%=externalLink%>"><%=externalLink%></a></td>
    </tr>
    <tr>
        <td class="leftCol-med">Tags</td>
        <td>
        <div id="tagList1">
            <%=tagString%>
        </div>
        </td>
    </tr>
    <tr>
    <td>

  </td></tr>
</table>



<a onclick="loadViewUI('../registry/custom/dia/dia_edit_ajaxprocessor.jsp', '<%=cPath%>')">Edit Document Details</a>

<br/>
